/**
 * @file   attribute.cpp
 * @author wolfhead <wolfhead@wolfhead-laptop>
 * @date   Fri Oct 21 15:13:48 2011
 * 
 * @brief  
 * 
 * 
 */
#include <sstream>
#include "error.h"
#include "attribute.h"
#include "parser.h"
#include "parser_factory.h"

using namespace PP;

Attribute::Attribute(const AttributeConfig& config)
    :config_(config)
{
}

Attribute::~Attribute()
{
}


const AttributeConfig& Attribute::GetConfig() const
{
    return config_;
}

const std::string& Attribute::GetName() const
{
    return config_.name;
}

int Attribute::Initialize(ParserFactory * pParserFactory)
{
    Parser * pParser = pParserFactory->CreateParser(
        config_.type, config_.length);

    if (!pParser)
    {
        return Error::ATTR_CREATE_PARSER_FAIL;
    }

    pParser_ = pParser;

    return Error::SUCCESS;
}

Parser * Attribute::GetParser() const
{
    return pParser_;
}

std::string Attribute::ToString() const
{
    std::ostringstream oss;
    oss << "Attribute\t" << config_.ToString();
    return oss.str();
}

